package com.j.lemon.learn.pulsar;

import com.alibaba.fastjson.JSON;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.common.policies.data.PersistentTopicInternalStats;
import org.apache.pulsar.common.policies.data.RetentionPolicies;
import org.apache.pulsar.common.policies.data.TopicStats;

import java.util.List;

/**
 * @author lijunjun
 */
public class AdminTest {
    public static void main(String[] args) {
        try (PulsarAdmin admin = PulsarUtils.getAdmin()) {
            List<String> tenants = admin.tenants().getTenants();
            System.out.println(tenants);
            String topic = "persistent://4a/audit/gather-test-zzy54";
            TopicStats stats = admin.topics().getStats(topic, true);
            System.out.println(JSON.toJSONString(stats));

            String internalInfo = admin.topics().getInternalInfo(topic);
            System.out.println(internalInfo);

            PersistentTopicInternalStats internalStats = admin.topics().getInternalStats(topic, true);
            System.out.println(JSON.toJSON(internalStats));

            RetentionPolicies retention = admin.namespaces().getRetention("4a/audit");
            System.out.println(JSON.toJSONString(retention));

        } catch (PulsarClientException | PulsarAdminException e) {
            e.printStackTrace();
        }


    }
}
